import React, { Component } from 'react'
import { Select } from 'antd'
import { getChannels } from 'api/channels'
export default class Channel extends Component {
  state = {
    channels: [],
  }
  render() {
    // console.log(this.props)
    return (
      <Select
        value={this.props.value}
        onChange={this.props.onChange}
        style={{ width: 200 }}
        placeholder="请选择文章频道"
      >
        {this.state.channels.map((obj) => {
          return (
            <Select.Option value={obj.id} key={obj.id}>
              {obj.name}
            </Select.Option>
          )
        })}
      </Select>
    )
  }
  async getChannelList() {
    const { data } = await getChannels()
    // console.log(data)
    this.setState({
      channels: data.channels,
    })
  }
  async componentDidMount() {
    this.getChannelList()
  }
}
